package com.pengweiwei.androidzygote.functions.utils.flexbox;

import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.Toast;

import com.google.android.flexbox.FlexboxLayout;
import com.pengweiwei.androidzygote.R;
import com.putong35.common.baseactfrag.activity.BaseActivity;
import com.putong35.common.utils.EasyToast;
import com.putong35.common.utils.ui.FlexboxChooseControler;

import butterknife.BindView;
import butterknife.OnClick;


public class FlexboxControllerActivity extends BaseActivity {

    @BindView(R.id.flexContainer)
    FlexboxLayout flexContainer;

    @OnClick(R.id.btnGetPositions)
    public void onBtnGetPositionsClicked() {
        String str = new String();
        for (Integer position : flexboxChooseControler.getSeletedItemPositions()) {
            str += "  " + position;
        }
        EasyToast.showToast(this, str);
    }

    @OnClick(R.id.btnCheck135)
    public void onBtnCheck135Clicked() {
        flexboxChooseControler.select(1, 3, 5);
    }

    @OnClick(R.id.btnSetMode)
    public void onBtnSetMode() {
        if (flexboxChooseControler.getMode() == FlexboxChooseControler.Mode.Multiple) {
            flexboxChooseControler.setMode(FlexboxChooseControler.Mode.Single);
            EasyToast.showToast(this, "设置单选模式成功");
        } else {
            flexboxChooseControler.setMode(FlexboxChooseControler.Mode.Multiple);
            EasyToast.showToast(this, "设置多选模式成功");
        }
    }

    FlexboxChooseControler flexboxChooseControler;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        String datas[] = {"111", "112", "113", "114", "115", "116", "117", "118", "119"};
        flexboxChooseControler = new FlexboxChooseControler(this,
                datas.length,
                flexContainer,
                R.layout.utils_flexbox_item,
                (position, itemView) -> {
                    Button btnData = (Button) itemView.findViewById(R.id.btnData);
                    btnData.setText(datas[position]);
                });
        flexboxChooseControler.select(1);
        flexboxChooseControler.setOnItemSelectedListener((position, itemView, selected) -> {
            EasyToast.showToast(FlexboxControllerActivity.this, "posi = " + position + "  selected == " + selected, Toast.LENGTH_SHORT);
        });

    }

    @Override
    public View createDataView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        return inflater.inflate(R.layout.activity_flexbox_controller, null);
    }
}
